<template>
  <div>
    <div>
      <el-row type="left" justify="space-around">
        <el-col :span="6"> </el-col>
        <el-col :span="11"></el-col>
        <el-col :span="7">
          <el-button
            size="small"
            type="primary"
            @click="buffer.Bufferfrom = true"
            >添加</el-button
          ></el-col
        >
      </el-row>
      <list
        :mylist="mylist"
        :clslist="clslist"
        @remove="removeMenu"
        @edit="editMenus"
      ></list>
      <inlist
        ref="formMenu"
        :mylist="mylist"
        :buffer="buffer"
        :bianji="bianji"
        @channel="rolelist"
      ></inlist>
    </div>
  </div>
</template>

<script>
import list from "../role/components/list";
import inlist from "../role/components/inlist";
export default {
  name: "",
  components: { list, inlist },
  data() {
    return {
      mylist: [],
      bianji: [],
      clslist: {},
      buffer: {
        Bufferfrom: false,
      },
    };
  },
  created() {},
  mounted() {
    this.rolelist();
  },
  methods: {
    rolelist() {
      this.$api.reqRole().then((res) => {
        console.log(res);
        this.mylist = res.data.list;
      });
    },
    editMenus(info) {
      let { index, row } = info;
      this.buffer.Bufferfrom = true;
      delete row.children;
      this.$refs.formMenu.form = JSON.parse(JSON.stringify(row));
      this.bianji = row.menus.split(",")
      
    },
    removeMenu(info) {
      let { index, row } = info;
      this.$confirm("此操作将删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          try {
            let res = await this.$api.roldel({ id: row.id });
            console.log("返回结果：", res);
            this.mylist = res.data.list;
          } catch (error) {
            console.log(error);
          }
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    editMenu() {},
  },
};
</script>
<style scoped lang="scss">
.el-row {
  margin-top: 20px;
}
</style>
